<?php

class SearchController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    public function productAction()
    {
        $request = $this->getRequest();
        
        $pb_mapper = new Application_Model_ProductBuyMapper();
        
        $_product = $this->getRequest()->getPost('product');
        $_category = $this->getRequest()->getPost('category');
        $_country = $this->getRequest()->getPost('country');
        
        if($_country == "" && $_category == ""){
        	$this->view->pbEntries = $pb_mapper->findByProductName($_product);
        }
        else if($_country == ""){
        	$this->view->pbEntries = $pb_mapper->findByNameCategoryCountry($_product, $_category, $_country, "category");
        }
        else if($_category == ""){
        	$this->view->pbEntries = $pb_mapper->findByNameCategoryCountry($_product, $_category, $_country, "country");
        }
        else{
        	$this->view->pbEntries = $pb_mapper->findByNameCategoryCountry($_product, $_category, $_country, "all");
        }

        $this->view->assign('action', $request->getBaseURL()."/product/sellerbid/lt/sb");
        $this->view->assign('title' , '產品搜尋結果 ');
        $this->view->assign('username' , '用戶名: ');
        $this->view->assign('new' , '新淨度: ');
    }

    public function userAction()
    {
    	$request = $this->getRequest();
    	
    	Zend_Date::setOptions(array('format_type' => 'php'));
        $date = new Zend_Date();
        
        $mbm_mapper = new Application_Model_MemberMapper();
        
        $_user = $this->getRequest()->getPost('user');
        $_country = $this->getRequest()->getPost('country');
        
    	if($_country == ""){
        	$this->view->mbmEntries = $mbm_mapper->findScheduleByUsername($_user);
        }
        else{
        	$this->view->mbmEntries = $mbm_mapper->findScheduleByUsernameCountry($_user, $_country, $date->toString('Y'), $date->toString('m'), $date->toString('d'));
        }
        
        $this->view->assign('title' , '用戶搜尋結果 ');
        $this->view->assign('action', $request->getBaseURL()."/member/profile/mid/");
        $this->view->assign('year' , $date->toString('Y'));
        $this->view->assign('month' , $date->toString('m'));
        $this->view->assign('day' , $date->toString('d'));
    }


}





